<?php include './application/views/common/zhs_header.php';?>
<?php include './application/views/common/zhs_usercenter_acnt.php';?>
<div class="inv_box w">
<?php include './application/views/common/zhs_usercenter_left.php';?>
  <div class="membd_right">
     <h3 class="membdrg_tit">交易密码</h3>
    <div class="mem_perbox">
    <form id="pwd_form">
<input type="hidden" name="act" value="submit">
   <ul class="perboxul">
   	<li><span>原始密码：</span><p><input  type="password" value="" maxlength="20" name="oldpwd" id="oldpwd">(初始交易密码与您注册时的登录密码一致)</p></li>
   	<li><span>新密码：</span><p><input placeholder='请输入8-16位字母和数字' type="password" value="" maxlength="20" name="newpwd" id="newpwd">(必须含有数字+字母，其中只允许~!#$^&?_字符)</p></li>
   	<li><span>确认密码：</span><p><input placeholder='请输入8-16位字母和数字' type="password" value="" maxlength="20" name="newpwd2" id="newpwd2"></p></li>
   	<li><span>手机验证码：</span><p><input type="text" id="ver_code" name="ver_code" style="width:45px;" maxlength="6">
   	<div id="phone_code"><a style="margin-top:0;" href="javascript:;" onclick="phoneSubmit();" >获取手机验证码</a></div>
					</p>
	</li>
   	<li><p style="margin-left:12px; margin-top:0;"><input type="button" style="height:30px;"  class="little_button"  size="30" value="确认修改" onclick="pwdSubmit();"></p><span> <a style="margin-top:22px;" href="/user/zhs_find/index.html">忘记交易密码</a></span></li>
   </ul>
   </form>
 </div>
 <script>
function pwdSubmit(){
	var options = {
		url : '/user/zhs_paypwd',
		clearForm :true,
		resetForm :false,
		beforeSubmit:  checkForm,
		dataType: "json",
		type:"post",
		success : function(ret) {
			if(ret.msg==''){
				$('#dialog').dialog({
					modal:true,
					title:'系统提示',
					buttons:{"确定":function(){$(this).dialog("close");}},
					close: function() {
						if(ret.url==''){
							window.location.reload();
						}else{
							location=ret.url;
						}
					}
				}); 
				$("#msg").html("操作成功");
			}else{
				$('#dialog').dialog({
					modal:true,
					title:'系统提示',
					buttons:{"确定":function(){$(this).dialog("close");}}
				}); 
				$("#msg").html(ret.msg);
			}
		}
	};
	$("#pwd_form").ajaxSubmit(options);
	return false;
}

function checkForm(){
	var pregName = /(?!^(\d+|[a-zA-Z]+|[~!#$^&?_]+)$)^[\w~!#$\^&?_]+$/;
	var err = '';
	if($('#oldpwd').val()==''){
		err = '请输入原始密码';
	}else if(!pregName.test($('#newpwd').val()) || $('#newpwd').val().length <=5){
		err = '无效新密码，必须含有数字+字母，其中只允许~!#$^&?_字符';
	}else if($('#newpwd2').val()==''){
		err = '请重复新密码';
	}else if($('#newpwd').val()!=$('#newpwd2').val()){
		err = '两次密码输入不一致';
	}else if($('#ver_code').val()==''){
		err = '请输入验证码';
	}
	if(err==''){
		return true;
	}else{
		$('#dialog').dialog({
			modal:true, //蒙层（弹出会影响页面大小）
			title:'系统提示',
			buttons:{"确定":function(){$(this).dialog("close");}},
			close: function() {
				//$("#pwd_form").resetForm();
			}
		}); 
		$("#msg").html(err);
		return false;
	}
}

function phoneSubmit(){
	$("#phone_code").html('处理中，请等待');
	$.ajax({
		type: "post",
		url: "/reg/sendsms.html",
		success: function(ret){
			if(ret.info == 1){
				phone_countdown();
			}else{
				$("#phone_code").html(ret.msg);
				setTimeout(function(){
				$("#phone_code").html('<a href="javascript:;" onclick="phoneSubmit();" style="color:#a71e32; text-decoration:underline"> 重新获取手机验证码</a>');
					
				},3000);
			}
		},
		dataType: "json"
	});	
}
function phone_countdown(){
	var count = 180;
	var countdown = setInterval(CountDown, 1000); 
	function CountDown() {
		$("#phone_code").html('手机验证码已发送,请等待 <font style="color:#a71e32;">'+count+"</font>秒");
		if (count == 0) {
			$("#phone_code").html('<a href="javascript:;" onclick="phoneSubmit();" style="color:#a71e32; text-decoration:underline"> 重新获取手机验证码</a>');
			clearInterval(countdown);
		}
		count--;
	}
}

</script>
  </div>
</div> 

<?php include './application/views/common/zhs_footer.php';?>
<?php include './application/views/common/zhs_right.php';?>

